package com.gwnet.rider.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gwnet.common.core.domain.ResponseResult;
import com.gwnet.rider.domain.bo.GrabOrderBO;
import com.gwnet.rider.domain.bo.MinuteBO;
import com.gwnet.rider.domain.bo.OrderPageBO;
import com.gwnet.rider.service.GrabOrderService;
import com.gwnet.shop.domain.OrderInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 接单记录 前端控制器
 * </p>
 *
 * @author WangLiang
 * @since 2024-07-31
 */
@RestController
@RequestMapping("/grabOrder")
public class GrabOrderController {

    private final GrabOrderService grabOrderService;


    public GrabOrderController(GrabOrderService grabOrderService) {
        this.grabOrderService = grabOrderService;
    }


    /**
     * 分页查询待抢单列表
     * @param pageBO
     * @return
     */
    @PostMapping("/grabOrderPage")
    public ResponseResult<IPage<OrderInfo>> orderPage(@RequestBody OrderPageBO pageBO){
        IPage<OrderInfo> page = grabOrderService.orderPage(pageBO);
        return ResponseResult.success(page);
    }

    /**
     * 抢单
     * @param grabOrderBO
     * @return
     */
    @PostMapping("/grabOrder")
    public ResponseResult<OrderInfo> grabOrder(@RequestBody GrabOrderBO grabOrderBO){
        OrderInfo orderInfo = grabOrderService.grabOrder(grabOrderBO);
        return ResponseResult.success(orderInfo);
    }

    /**
     * 超时没有人接单的订单要推送到消息队列中，由中台进行强制派单
     * @param minuteBO 超时的标准，多少分钟算超时
     * @return 待优化，响应的只能是批量推送结果，成功与否，不能响应这么多数据
     */
    @PostMapping("/timeOutOrderPushToMQ")
    public ResponseResult<List<OrderInfo>> timeOutOrderPushToMQ(@RequestBody MinuteBO minuteBO){
        List<OrderInfo> list = grabOrderService.timeOutOrderPushToMQ(minuteBO.getMinute());
        return ResponseResult.success(list);
    }
}

